How to add items to a List<T> collection in C#?
How to add items to a List collection in C#?
40503-Nov-2023
Updated on 20-Nov-2023
Home / DeveloperSection / Forums / How to add items to a List collection in C#?
How to add items to a List<T> collection in C#?
Aryan Kumar
20-Nov-2023Certainly! In C#, you can add items to a list using the Add method. Here's a simple example:
In this example, we create a list of integers (List<int> myNumbers) and use the Add method to add three numbers (10, 20, and 30) to the list. The foreach loop is then used to iterate through the list and display its contents.